package com.pls.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.google.gson.Gson;
import com.pls.actionAdapter.PlsAdapter;
import com.pls.domain.WorkstationMap;
import com.pls.javabeans.EmployeeDetailsBean;
import com.pls.javabeans.EmployeeWorkstationBean;

/**
 * Servlet implementation class GetSearchSeatMapServlet
 */
@WebServlet("/GetSearchSeatMapServlet")
public class GetSearchedSeatMapServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	Logger logger = Logger.getLogger(GetEmployeeDetailsServlet.class);

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetSearchedSeatMapServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void process(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		logger.debug("process method for servlet entered.");
		HttpSession session = request.getSession();
		// Gets the context of the current user
		// Employee currentUser = (Employee) session.getAttribute("user");
		PlsAdapter adapter = new PlsAdapter();

		String firstName = request.getParameter("firstName");
		String lastName = request.getParameter("lastName");
		
		EmployeeWorkstationBean bean = new EmployeeWorkstationBean();
		bean = adapter.getWorkstationMap(firstName, lastName);

		String json = null;
		json = new Gson().toJson(bean);

		response.setContentType("application/json");
		response.setCharacterEncoding("UTF-8");
	
		logger.debug("process method for servlet exited.");
		response.getWriter().write(json);

		// sysout Tests
		// System.out.println(bean.getSearchResults().get(0).getFirstName());

		// RequestDispatcher goToHome = request
		// .getRequestDispatcher("pageTestForSearch.jsp");
		//
		// goToHome.forward(request, response);

		// else {
		//
		// RequestDispatcher logInFailDispatcher = request
		// .getRequestDispatcher("login.jsp");
		// request.setAttribute("errorMessage",
		// "Unauthorized access. Please log in.");
		// logInFailDispatcher.forward(request, response);
		//
		// }

	}

}
